package cm.example.shoppingplatformspringboot.service;

import cm.example.shoppingplatformspringboot.entity.Invoice;
import cm.example.shoppingplatformspringboot.mapper.InvoiceMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class InvoiceService {
    @Resource
    private InvoiceMapper invoiceMapper;

    // 创建发票
    @Transactional
    public int createInvoice(Invoice invoice) {
       return invoiceMapper.insertInvoice(invoice);
    }

    // 更新发票（根据订单ID）
    @Transactional
    public Invoice updateInvoice(Invoice invoice) {
        invoiceMapper.updateInvoice(invoice);
        return getInvoiceById(invoice.getOrder_id());
    }

    // 获取发票详情（根据订单ID）
    public Invoice getInvoiceById(Integer order_id) {
        return invoiceMapper.getInvoiceById(order_id);
    }
}